﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QuanLyHocPhi.Entity;
using System.Data.SqlClient;
using System.Data;

namespace QuanLyHocPhi.DAL
{
   public class SINHVIEN_LOPHOC_DAO
    {
        private const string SQL_INSERT = "insert into SINHVIEN_LOPHOC(MA_SV, MA_LOP_HOC) values(@MA_SV, @MA_LOP_HOC)";
        private const string SQL_DELETE = "delete from SINHVIEN_LOPHOC where MA_SV = @MA_SV AND MA_LOP_HOC = @MA_lOP_HOC";


        //parameter
        private const string PARM_STUDENT_ID = "@MA_SV";
        private const string PARM_CLASS_ID = "@MA_LOP_HOC";


        public Boolean Insert(SINHVIEN_LOPHOC svlp)
        {
            {
                SqlParameter[] parms;
                parms = new SqlParameter[] {    
                                                new SqlParameter(PARM_STUDENT_ID, SqlDbType.NVarChar),
											 new SqlParameter(PARM_CLASS_ID, SqlDbType.NVarChar) };

                parms[0].Value = svlp.SINH_VIEN.MA_SV;
                parms[1].Value = svlp.MA_LOP_HOC.MA_LOP_HOC;

                try
                {
                    int result = 0;
                    SqlConnection conn = new SqlConnection(SQLDBHelper.CONN_STRING);
                    result = SQLDBHelper.ExecuteNonQuery(conn, CommandType.Text, SQL_INSERT, parms);
                    if (conn.State == ConnectionState.Open)
                        conn.Close();
                    return (result > 0 ? true : false);
                }
                catch (Exception e)
                {
                    throw e;
                }


            }

        }
        public bool Delete(int MA_SV , int MA_LOP_HOC)
        {
            SqlParameter[] parms;
            parms = new SqlParameter[] { new SqlParameter(PARM_CLASS_ID, SqlDbType.Int),
                                         new SqlParameter(PARM_STUDENT_ID, SqlDbType.Int) };
            parms[0].Value = MA_SV;
            parms[1].Value = MA_LOP_HOC;

            try
            {
                int result = 0;
                result = SQLDBHelper.ExecuteNonQuery(SQLDBHelper.CONN_STRING,
                    CommandType.Text, SQL_DELETE, parms);
                return (result > 0 ? true : false);
            }
            catch (Exception e)
            {
                throw e;
            }
        }

    }

}